package com.fw.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fw.annotation.Log;
import com.fw.core.controller.BaseController;
import com.fw.core.domain.AjaxResult;
import com.fw.enums.BusinessType;
import com.fw.system.admin.domain.TbRuleDates;
import com.fw.system.admin.service.ITbRuleDatesService;
import com.fw.utils.poi.ExcelUtil;
import com.fw.core.page.TableDataInfo;

/**
 * 数据规则Controller
 * 
 * @author xxx
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/admin/rule_dates")
public class TbRuleDatesController extends BaseController
{
    @Autowired
    private ITbRuleDatesService tbRuleDatesService;

    /**
     * 查询数据规则列表
     */
    @PreAuthorize("@ss.hasPermi('admin:rule_dates:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbRuleDates tbRuleDates)
    {
        startPage();
        List<TbRuleDates> list = tbRuleDatesService.selectTbRuleDatesList(tbRuleDates);
        return getDataTable(list);
    }

    /**
     * 导出数据规则列表
     */
    @PreAuthorize("@ss.hasPermi('admin:rule_dates:export')")
    @Log(title = "数据规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbRuleDates tbRuleDates)
    {
        List<TbRuleDates> list = tbRuleDatesService.selectTbRuleDatesList(tbRuleDates);
        ExcelUtil<TbRuleDates> util = new ExcelUtil<TbRuleDates>(TbRuleDates.class);
        return util.exportExcel(list, "rule_dates");
    }

    /**
     * 获取数据规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:rule_dates:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tbRuleDatesService.selectTbRuleDatesById(id));
    }

    /**
     * 新增数据规则
     */
    @PreAuthorize("@ss.hasPermi('admin:rule_dates:add')")
    @Log(title = "数据规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRuleDates tbRuleDates)
    {
        return toAjax(tbRuleDatesService.insertTbRuleDates(tbRuleDates));
    }

    /**
     * 修改数据规则
     */
    @PreAuthorize("@ss.hasPermi('admin:rule_dates:edit')")
    @Log(title = "数据规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRuleDates tbRuleDates)
    {
        return toAjax(tbRuleDatesService.updateTbRuleDates(tbRuleDates));
    }

    /**
     * 删除数据规则
     */
    @PreAuthorize("@ss.hasPermi('admin:rule_dates:remove')")
    @Log(title = "数据规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbRuleDatesService.deleteTbRuleDatesByIds(ids));
    }
}
